﻿
using LeaderCCSLaserUI.Services;
using System.Threading;
using System;
using LeaderCCSLaserUI.Views.Dialogs;
using LeaderCCSLaserUI.ViewModels.Dialogs;

using LeaderCCSLaserUI.Models;
using System.Configuration;
using LeaderCCSLaserUI.ViewModels.Dialogs.PartNum;
using LeaderCCSLaserUI.Views.Dialogs.PartNum;
using LeaderCCSLaserUI.Views.Dialogs.WorkPoint;
using LeaderCCSLaserUI.ViewModels.Dialogs.WorkPoint;
using Prism.Modularity;
using LeaderCCSLaserUI.Data.Common.Services;
using LeaderCCSLaserUI.Views.Dialogs.BarcodeScan;
using LeaderCCSLaserUI.ViewModels.Dialogs.BarcodeScan;
using LeaderCCSLaserUI.Views.Dialogs.VisionProgram;
using LeaderCCSLaserUI.ViewModels.Dialogs.VisionProgram;

namespace LeaderCCSLaserUI
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        private static Mutex _mutex = null;
        protected override void OnStartup(StartupEventArgs e)
        {
            const string appName = "LeaderCCSLaserUI";
            bool createdNew;

            _mutex = new Mutex(true, appName, out createdNew);

            if (!createdNew)
            {
                MessageBox.Show("LeaderCCSLaserUI软件已开启", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                //app is already running! Exiting the application  
                Environment.Exit(-1);
            }

            base.OnStartup(e);
        }
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterSingleton<DrawROI>();

            containerRegistry.Register<IDialogHostService, DialogHostService>();

            containerRegistry.RegisterForNavigation<LeftHandView, LeftHandViewModel>("Left");
            containerRegistry.RegisterForNavigation<RightHandView, RightHandViewModel>("Right");
            containerRegistry.RegisterForNavigation<WorkMapView, WorkMapViewModel>();

            containerRegistry.RegisterSingleton<IGTSCardService, GTSCardService>("GTSCard");
            containerRegistry.RegisterSingleton<IPLCService, PLCService>("PLC");
            containerRegistry.RegisterSingleton<IServoModbusService, ServoModbusService>("ServoModbus");

            containerRegistry.RegisterSingleton<IGetBarcodeService, GetBarcodeHttpService>();
            containerRegistry.RegisterSingleton<IHIKCameraService, HIKCameraService>("LeftCamera");
            containerRegistry.RegisterSingleton<IHIKCameraService, HIKCameraService>("RightCamera");

            containerRegistry.RegisterDialog<PasswordDialog, PasswordDialogViewModel>();
            containerRegistry.RegisterDialog<AxisDialog, AxisDialogViewModel>();
            containerRegistry.RegisterDialog<PLCDialog, PLCDialogViewModel>();
            containerRegistry.RegisterDialog<WorkPointDialog, WorkPointDialogViewModel>();
            containerRegistry.RegisterDialog<ParameterDialog, ParameterDialogViewModel>();
            containerRegistry.RegisterDialog<CameraCalibDialog, CameraCalibDialogViewModel>();
            containerRegistry.RegisterDialog<CameraVisionDialog, CameraVisionDialogViewModel>();
            containerRegistry.RegisterDialog<VisionProgramDialog, VisionProgramDialogViewModel>();
            containerRegistry.RegisterDialog<BarcodeScanDialog, BarcodeScanDialogViewModel>();
            containerRegistry.RegisterDialog<ZControlDialog, ZControlDialogViewModel>();


            containerRegistry.RegisterDialog<PartNumDialog, PartNumDialogViewModel>();
            containerRegistry.RegisterDialog<AddNewPartNumDialog, AddNewPartNumDialogViewModel>();
            containerRegistry.RegisterDialog<AddVisionFunctionDialog, AddVisionFunctionDialogViewModel>();
            containerRegistry.RegisterDialog<FunctionShapeModelDialog, FunctionShapeModelDialogViewModel>();
            containerRegistry.RegisterDialog<FunctionPreProcessingDialog, FunctionPreProcessingDialogViewModel>();
            containerRegistry.RegisterDialog<FunctionBlobCircleDialog, FunctionBlobCircleDialogViewModel>();
            containerRegistry.RegisterDialog<FunctionTwoLineIntersectionDialog, FunctionTwoLineIntersectionDialogViewModel>();
            containerRegistry.RegisterDialog<FunctionNccModelDialog, FunctionNccModelDialogViewModel>();
            containerRegistry.RegisterDialog<FunctionBlobRectangleDialog, FunctionBlobRectangleDialogViewModel>();
            containerRegistry.RegisterDialog<ProgramManageDialog, ProgramManageDialogViewModel>();

            containerRegistry.RegisterDialog<AddPointDialog, AddPointDialogViewModel>();
            containerRegistry.RegisterDialog<VisionAlarmDialog, VisionAlarmDialogViewModel>();
            containerRegistry.RegisterDialog<AddBarcodePointDialog, AddBarcodePointDialogViewModel>();
            containerRegistry.RegisterDialog<MessageAlarmDialog, MessageAlarmDialogViewModel>();
        }
        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new ConfigurationModuleCatalog();
        }
    }
}
